package com.voiceblog.action;

import java.util.Date;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.voiceblog.dao.BlogDAO;
import com.voiceblog.model.PhotoDAO;
import com.voiceblog.model.Users;
import com.voiceblog.model.UserDAO;
import com.voiceblog.model.Blog;

public class BlogHomeAction extends ActionSupport {
	private BlogDAO blogDAO;
	private UserDAO userDAO;
	private PhotoDAO photoDAO;
	public UserDAO getUserDAO() {
		return userDAO;
	}

	public void setUserDAO(UserDAO userDAO) {
		this.userDAO = userDAO;
	}

	public BlogDAO getBlogDAO() {
		return blogDAO;
	}

	public Blog getBlog() {
		return blog;
	}

	private Blog blog;

	public void setBlogDAO(BlogDAO blogDAO) {
		this.blogDAO = blogDAO;
	}

	public void setBlog(Blog blog) {
		this.blog = blog;
	}

	@Override
	public String execute() throws Exception {
		ActionContext actionContext = ActionContext.getContext();
		Map session = actionContext.getSession();
		blog = (Blog) session.get("blogList");
		if (blog == null) {
			blog = new Blog();
		}
		Users user=userDAO.findById("greg");
		 blog.setArticleContent("fdf");
		 blog.setArticleTitle("dfd");
		 blog.setVisitNumber(5);
		 blog.setUser(user);
		 blog.setArticlePublishDate(new Date());
		 blogDAO.save(blog);
		//blog = blogDAO.findById(1);
		//System.out.print(blog.getArticleTitle());

		//session.put("blogList", blog);
		return SUCCESS;

	}

	public PhotoDAO getPhotoDAO() {
		return photoDAO;
	}

	public void setPhotoDAO(PhotoDAO photoDAO) {
		this.photoDAO = photoDAO;
	}

}
